<?php
class Db_Adapter_MySQL implements Db_Interface
{
	private $_link = NULL;
	public $prefix = "";

	public function __construct(
		$host =       'localhost',
		$user =       '',
		$password =   '',
		$database =   'database',
		$driver =     'mysql',
		$persistent = false,
		$prefix =     '',
		$encoding =   'utf8'
	)
	{
		$this->prefix = $prefix;

		if ($persistent)
		{
			$this->_link = mysql_pconnect($host, $user, $password);
		}
		else
		{
			$this->_link = mysql_connect($host, $user, $password);
		}
	}

	public function database($s)
	{
		$this->query('USE ' . $s);
	}

	public function query($s)
	{
		$result = mysql_query($s, $this->_link);
		if (is_resource($result))
		{
			return new Db_Statement_MySQL($result);
		}
		return $result;
	}

	public function quote($s)
	{
		$r = mysql_escape_string($s);
		if (is_string($s))
		{
			$r = "'" . $r . "'";
		}
		return $r;
	}

	public function encoding($s)
	{
		$this->query('SET NAMES ' . $s);
	}
}